const { defineConfig } = require("@vue/cli-service");
const path = require('path')
function resolve(paths) {
  return path.resolve(paths)
}
let baseURL = process.env.VUE_APP_BASEURL //获取环境中的服务器地址
let env = process.env.NODE.ENV;
module.exports = defineConfig({
  publicPath:"./",
  transpileDependencies: true,
  lintOnSave: false,
  outputDir:env==='test' ? "testDist" : "dist",
  // 配置代理
  devServer:{
    proxy:{
      "/api":{
        target:baseURL,
        pathRewrite:{
          "^/api":""
        }
      }
    }
  },
  chainWebpack: (config) => { //配置别名,合并webpack配置
    config.resolve.alias
      .set('&', resolve('src'))
      .set('assets', resolve('src/assets'))
      .set('components', resolve('src/components'))
      .set('layout', resolve('src/layout'))
      .set('base', resolve('src/base'))
      .set('static', resolve('src/static'))

    //设置打包hash
    // config.output
    //   .filename(
    //     `assets/js/[name].${process.env.VUE_APP_APPVERSION}.${+new Date()}.js`
    //   )
    //   .chunkFilename(
    //     `assets/js/[name].${process.env.VUE_APP_APPVERSION}.${+new Date()}.js`
    //   )
    //   .end();

    // 如果filenameHashing设置为了false，可以通过这段代码给打包出的css文件增加hash值
    // config.plugin('extract-css').tap(args => [{
    //   filename: `assets/css/${process.env.VUE_APP_VERSION}.${+new Date()}.[name].css`,
    //   chunkFilename: `assets/css/${process.env.VUE_APP_VERSION}.${+new Date()}.[name].css`
    // }])
  }
});
